package com.zhang.common.security.handle;

import cn.hutool.core.collection.CollUtil;
import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.Authentication;

/**
 * @ClassName AbstractAuthenticationSuccessEventHandler
 * @Description 认证成功事件处理器
 * @Author zsw
 * @Date 2019/10/28 15:39
 * @Version V1.0
 **/

public abstract class AbstractAuthenticationSuccessEventHandler  implements ApplicationListener<AuthenticationSuccessEvent> {

    @Override
    public void onApplicationEvent(AuthenticationSuccessEvent authenticationSuccessEvent) {
        Authentication authentication = (Authentication) authenticationSuccessEvent.getSource();
        if (CollUtil.isNotEmpty(authentication.getAuthorities())) {
            handle(authentication);
        }
    }
    

    /**
     * @Author  zsw
     * @Description 处理登录成功方法
     * @Date 2019/10/28 16:10
     * @param authentication 登录对象
     * @return
      **/
    public abstract void handle(Authentication authentication);
}